package com.example.medicine.controller;


import com.example.medicine.Bean.dilixinxi;
import com.example.medicine.Mapper.dlxxMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value="/dlxx")
public class DlxxController {
    @Autowired
    private dlxxMapper dlxxMapper;
    Subject subject = SecurityUtils.getSubject();

    /**
     * 接收传值请求，返回地理信息json
     */
    @RequiresPermissions("地理信息库")
    @GetMapping("/")
    public List<dilixinxi> getDlxxList() {
        log.info("getDlxxList获取地理信息");
        // 从数据库中获取数据
        return dlxxMapper.getAll();
    }

    /**
     * 接收新建请求，向dlxx表中插入数据
     */
    @RequiresPermissions("地理信息库")
    @PostMapping("/")
    public void insertDlxx(@RequestBody dilixinxi dlxx){
        log.info("insertDlxx添加地理信息start");
        dlxx.setCreateuser((String) subject.getPrincipal());
        dlxxMapper.insert(dlxx);
        log.info("insertDlxx添加地理信息end");
    }

    /**
     * 接收更新请求，根据id值更新dlxx表内容
     */
    @RequiresPermissions("地理信息库")
    @PutMapping("/")
    public void updateDlxx(@RequestBody dilixinxi dlxx){
        log.info("updateDlxx修改地理信息start");
        dlxxMapper.update(dlxx);
        log.info("updateDlxx修改地理信息end");
    }

    @RequiresPermissions("地理信息库")
    @PutMapping("/{id}")
    public void updateShenhe(@PathVariable int id){
        log.info("updateShenhe地理信息审核");
        dilixinxi dlxx =new dilixinxi();
        dlxx.setId(id);
        dlxx.setShr((String) subject.getPrincipal());
        dlxx.setShenhe("通过");
        dlxxMapper.updateShenhe(dlxx);
    }

    @RequiresPermissions("地理信息库")
    @DeleteMapping("/{id}")
    public void deleteDlxx(@PathVariable int id){
        log.info("deleteDlxx地理信息删除");
        dlxxMapper.deleteById(id);
    }
}
